package com.boat.ai.rag.Ingestion.strategy;

import com.boat.ai.domain.enums.FileTypeEnum;
import io.quarkus.runtime.Startup;
import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Instance;
import jakarta.inject.Inject;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

@Startup
@ApplicationScoped
public class ParseStrategyFactory {

    @Inject
    Instance<ParseStrategy> strategies;

    private final Map<String, ParseStrategy> parseStrategyMap = new ConcurrentHashMap<>();

    @PostConstruct
    void init() {
        for (ParseStrategy strategy : strategies) {
            parseStrategyMap.put(strategy.type()
                    .name(), strategy);
        }
    }

    public ParseStrategy getStrategy(FileTypeEnum fileTypeEnum) {
        return parseStrategyMap.getOrDefault(fileTypeEnum.name(), parseStrategyMap.get(FileTypeEnum.TEXT.name())); // fallback
    }
}
